#ifndef FOREIGNKEYCONSTRAINT_H
#define FOREIGNKEYCONSTRAINT_H

#include "tableconstraint.h"

#include <string>
using namespace std;

// forward declarations
class ColumnList;
class Column;

/*
    Class: ForeignKeyConstraint
    Subclass of TableConstraint that represents a foreign key of an SQL Table.

    See also
*/
class ForeignKeyConstraint : public TableConstraint
{
    /* Section: public */
    public:
        /*
            Constructor: Default constructor.
            Initializes the object.
        */
        ForeignKeyConstraint(ColumnList * table_columns = NULL, ColumnList * referenced_columns = NULL, const string & referenced_table = "");

        /*
            Destructor: Default destructor.
            Destroy the object.
        */
        virtual ~ForeignKeyConstraint();

        /*
            Constructor: Copy constructor.
            Initializes the object as a copy from other ForeignKeyConstraint object.

            Parameters:
                other   -   ForeignKeyConstraint object to copy from.
        */
        ForeignKeyConstraint(const ForeignKeyConstraint & other);

        /*
            Method: Clone
            Returns:
                 A pointer to a clone of the ForeignKeyConstraint.
        */
        virtual TableConstraint * clone();

        /*
            Method: ToString
            Returns:
                A string representation of the ForeignKeyConstraint.
        */
        virtual string toString();

        /*
            Method: GetReferencedColumn
            Gets the name of the referenced column by the column name given.

            Returns:
                true if the referenced column exits. False in other case.

            Parameters:
                column - name of the column
                referenced  -   output parameter: the name of the referenced column.
        */
        bool getReferencedColumn(const string & column, string & referenced);

        /*
            Method: GetTable
            Returns:
                the name of the Table that contains the referenced columns.
        */
        string getTable();

        /*
            Method: SetTableColumns
            Sets the table columns that compose the foreign key. Destroy the previous ColumnList if any.

            Parameters:
                columns - ColumnList that contains the columns that compose the foreign key.
        */
        void setTableColumns(ColumnList * columns);

        /*
            Method: SetReferencedColumns
            Sets the referenced columns.

            Parameters:
                columns - ColumnList that contains the referenced columns.
        */
        void setReferencedColumns(ColumnList * columns);

        /*
            Method: SetTable
            Sets the name of the table that contains de referenced columns.

            Parameters:
                table - Name of the table.
        */
        void setTable(const string & table);

        /*
            Method: Add
            Add a new pair <column, referenced_column>

            Parameters:
                column  -   column of the table.
                referenced  -   column of referenced.
        */
        void add(const string & column, const string & referenced);

        /*
            Method: Add
            Add a new pair <column, referenced_column>

            Parameters:
                column  -   column of the table.
                referenced  -   column of referenced.
        */
        void add(Column * column, Column * referenced);


    /* Section private */
    private:
        /*
            Variable: table_columns
            Type: ColumnList
            Columns of the table that compose the foreign key.
        */
        ColumnList * table_columns;

        /*
            Variable: referenced_columns
            Type: ColumnList
            Referenced columns of other Table.
        */
        ColumnList * referenced_columns;

        /*
            Variable: referenced_table
            Type: string
            Table that contains the referenced columns.
        */
        string referenced_table;
};

#endif // FOREIGNKEYCONSTRAINT_H
